home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / glob.test < prev    next >
Text File  |  1992-12-23  |  4KB  |  108 lines

  1. # Commands covered:  glob
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /rel/cvsfiles/devo/tcl/tests/glob.test,v 1.1.1.1 1992/11/07 04:46:55 zoo Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. # First, create some subdirectories to use for testing.
  21.  
  22. exec rm -rf globTest
  23. exec mkdir globTest globTest/a1 globTest/a2 globTest/a3
  24. exec mkdir globTest/a1/b1 globTest/a1/b2 globTest/a2/b3
  25. exec cat << abc > globTest/x1.c
  26. exec cat << abc > globTest/y1.c
  27. exec cat << abc > globTest/z1.c
  28. exec cat << abc > "globTest/weird name.c"
  29. exec cat << abc > globTest/.1
  30. exec cat << abc > globTest/a1/b1/x2.c
  31. exec cat << abc > globTest/a1/b2/y2.c
  32.  
  33. test glob-1.1 {simple globbing} {glob a} a
  34. test glob-1.2 {simple globbing} {glob aaa bbb ccc} {aaa bbb ccc}
  35.  
  36. test glob-2.1 {globbing with braces} {glob "{a1,a2}"} "a1 a2"
  37. test glob-2.2 {globbing with braces} {glob a/{x,y}{123,456}/z} \
  38.     "a/x123/z a/x456/z a/y123/z a/y456/z"
  39.  
  40. test glob-3.1 {asterisks and question marks} {lsort [glob g*/*.c]} \
  41.     "{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c"
  42. test glob-3.2 {asterisks and question marks} {lsort [glob globTest/?1.c]} \
  43.     "globTest/x1.c globTest/y1.c globTest/z1.c"
  44. test glob-3.3 {asterisks and question marks} {lsort [glob */*/*/*.c]} \
  45.     "globTest/a1/b1/x2.c globTest/a1/b2/y2.c"
  46. test glob-3.4 {asterisks and question marks} {lsort [glob globTest/*]} \
  47.     "globTest/a1 globTest/a2 globTest/a3 {globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c"
  48. test glob-3.5 {asterisks and question marks} {lsort [glob globTest/.*]} \
  49.     "globTest/. globTest/.. globTest/.1"
  50. test glob-3.6 {asterisks and question marks} {lsort [glob globTest/*/*]} \
  51.     "globTest/a1/b1 globTest/a1/b2 globTest/a2/b3"
  52. test glob-3.7 {asterisks and question marks} {lsort [glob {globTest/[xy]1.*}]} \
  53.     "globTest/x1.c globTest/y1.c"
  54.  
  55. # The tests immediately below can only be run at Berkeley, where
  56. # the file-system structure is well-known.
  57.  
  58. if {[string compare [glob ~] /users/ouster] == 0} {
  59.     test glob-4.1 {tildes} {glob ~/.csh*} "/users/ouster/.cshrc"
  60.     test glob-4.2 {tildes} {glob ~/.csh*} "/users/ouster/.cshrc"
  61.  
  62. test glob-5.1 {error conditions} {
  63.     list [catch {glob} msg] $msg
  64. } {1 {wrong # args: should be "glob ?-nocomplain? name ?name ...?"}}
  65. test glob-5.2 {error conditions} {
  66.     list [catch {glob a/{b,c,d}/\{} msg] $msg
  67. } {1 {unmatched open-brace in file name}}
  68. test glob-5.3 {error conditions} {
  69.     list [catch {glob goo/*} msg] $msg
  70. } {1 {no files matched glob pattern "goo/*"}}
  71. test glob-5.4 {error conditions} {
  72.     list [catch {glob goo/* x*z foo?q} msg] $msg
  73. } {1 {no files matched glob patterns "goo/* x*z foo?q"}}
  74. test glob-5.5 {error conditions} {
  75.     list [catch {lsort [glob globTest/*.c goo/*]} msg] $msg
  76. } {0 {{globTest/weird name.c} globTest/x1.c globTest/y1.c globTest/z1.c}}
  77. test glob-5.6 {error conditions} {
  78.     list [catch {glob ~no-one} msg] $msg
  79. } {1 {user "no-one" doesn't exist}}
  80. test glob-5.7 {error conditions} {
  81.     set home $env(HOME)
  82.     unset env(HOME)
  83.     set x [list [catch {glob ~/*} msg] $msg]
  84.     set env(HOME) $home
  85.     set x
  86. } {1 {couldn't find HOME environment variable to expand "~/*"}}
  87.  
  88. exec chmod 000 globTest
  89. if {$user != "root"} {
  90.     test glob-6.1 {setting errorCode variable} {
  91.     string tolower [list [catch {glob globTest/*} msg]  $msg $errorCode]
  92.     } {1 {couldn't read directory "globtest": permission denied} {unix eacces {permission denied}}}
  93. }
  94. exec chmod 755 globTest
  95.  
  96. test glob-7.1 {-nocomplain option} {
  97.     list [catch {glob -nocomplai} msg] $msg
  98. } {0 -nocomplai}
  99. test glob-7.2 {-nocomplain option} {
  100.     list [catch {glob -nocomplain} msg] $msg
  101. } {1 {wrong # args: should be "glob ?-nocomplain? name ?name ...?"}}
  102. test glob-7.3 {-nocomplain option} {
  103.     list [catch {glob -nocomplain goo/*} msg] $msg
  104. } {0 {}}
  105.  
  106. exec rm -rf globTest
  107.